<script setup lang="ts">
import carousel from "@/pages/home/carousel/carousel.vue"
import search from "@/pages/home/search/search.vue"
import level from "@/pages/home/level/level.vue"
import Region from "@/pages/home/region/region.vue";
import Card from "@/pages/home/card/card.vue";
import {ref} from "vue";
import useHomeStore from "@/store/home";
import {storeToRefs} from "pinia";
import Tip from "@/pages/home/tip/tip.vue";


const currentPage = ref(1)
const pageSize = ref(10)
const hosType = ref('')
const districtCode = ref('')

const homeStore = useHomeStore();
const {totalCount} = storeToRefs(homeStore);

const handleSizeChange = () => {
  homeStore.getHospitalData(currentPage.value, pageSize.value,hosType.value,districtCode.value)
}

const handleCurrentChange = () => {
  homeStore.getHospitalData(currentPage.value, pageSize.value,hosType.value,districtCode.value)
}


const handlerLevel = (value: string) => {
  hosType.value = value
  homeStore.getHospitalData(currentPage.value, pageSize.value,hosType.value,districtCode.value)
}

const handlerRegion = (value: string) => {
  districtCode.value = value
  homeStore.getHospitalData(currentPage.value, pageSize.value,hosType.value,districtCode.value)
}


</script>

<template>
  <div class="home">
    <!--    banner图-->
    <carousel/>
    <!--    搜索框-->
    <search/>
    <!--    医院信息-->
    <el-row>
      <el-col :span="18" class="left">
        <!--        医院等级-->
        <level @handler-level="handlerLevel"/>
        <!--        医院地区-->
        <region @handler-region="handlerRegion"/>
        <!--        医院信息-->
        <card/>
        <!--        分页器-->
        <el-pagination
            v-model:current-page="currentPage"
            v-model:page-size="pageSize"
            :page-sizes="[10, 20, 30, 40]"
            layout="total, sizes, prev, pager, next, jumper"
            :total="totalCount"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
        />
      </el-col>
      <el-col :span="6">
       <tip/>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped lang="less">
.home {
  margin-bottom: 50px;

  .el-row {
    margin-top: 20px;
  }

  .left {
    padding-right: 20px;
  }

  .el-pagination {
    margin-top: 10px;
  }
}
</style>
